<template>
  <div class="app-container calendar-list-container">
    <vue-editor v-model="query.context" @imageAdded="editorUpload" useCustomImageHandler/>
    <el-button
      type="primary"
      style="margin-top:40px"
      :loading="loading.edit"
      @click="updateParameter"
    >确定</el-button>
  </div>
</template>

<script>
import { VueEditor } from "vue2-editor";
import {
  updateSystemParamter,
  getSystemParamter,
  fileUpload
} from "@/api/system";
export default {
  name: "system_tutorial",
  data() {
    return {
      loading: {
        edit: false
      },
      query: {
        systemType: 14,
        context: ""
      }
    };
  },
  components: {
    VueEditor
  },
  methods: {
    //富文本上传图片
    async editorUpload(file, Editor, cursorLocation, resetUploader) {
      if (file.size > 2 * 1024 * 1024) {
        this.$message.warning("图片不能大于2M");
        return;
      }
      const formData = new FormData();
      formData.append("file", file);
      formData.append("fileName", "richtxt");
      const res = await fileUpload(formData);
      Editor.insertEmbed(cursorLocation, "image", this.$uploadUrl + res.data);
      resetUploader();
    },

    // 获取用户协议
   async getParameter() {
      const { data } = await getSystemParamter({
        type: 14
      });
      this.query.context = data[0].parameter;
    },

    //修改用户协议
   async updateParameter() {
      if (!this.query.context) {
        this.$message.error("请输入内容");
        return;
      }
      const { data } = await updateSystemParamter({
        systemType: 14,
        parameter: this.query.context
      });
      this.$message.success("修改成功");
    }
  },
  created() {
    this.getParameter();
  }
};
</script>

<style>
</style>
